package com.jarchie.androiddev.utils

class DisplayUtil {

    companion object {

        /**
         * 获取屏幕宽度
         */
        fun getScreenWidth(): Int {
            return AppGlobals.getApplication().resources.displayMetrics.widthPixels
        }

        /**
         * 获取屏幕高度
         */
        fun getScreenHeight(): Int {
            return AppGlobals.getApplication().resources.displayMetrics.heightPixels
        }

        /**
         * dp转px
         */
        fun dp2px(dpValue: Int): Int {
            val scale = AppGlobals.getApplication().resources.displayMetrics.density
            return (dpValue * scale + 0.5f).toInt()
        }

        /**
         * px转dp
         */
        fun px2dp(pxValue: Int): Int {
            val scale = AppGlobals.getApplication().resources.displayMetrics.density
            return (pxValue / scale + 0.5f).toInt()
        }
    }
}
